Redis 3.2.8 安装与配置

 

在本章中,您将了解和学习Redis的环境安装设置。

一、RedHat 6.0 自定义安装


1、创建redis用户

Redis 默认的安装路径是/usr/local/redis,并且安装是root用户。

为安装在自定义的目录下,首先创建一个redis用户,并且修改密码。

[root@localhost home]# useradd -d /home/redis  -g redis -m redis
[root@localhost /]# passwd redis
Changing password for user redis.
New password: 

2、下载redis安装包

目前,redis官方的最新版本的是Redis 3.2.8版本。

下载完毕后使用tar命令解压到当前目录。

[redis@localhost ~]$ wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[redis@localhost ~]$ tar zxvf redis-3.2.8.tar.gz 

3、编译redis

进入安装目录下,执行make命令,编译成功后会显示下面内容。

编译后在目录下生成一个src目录,里面会有编译好的执行文件

[redis@localhost ~]$ cd redis-3.2.8
[redis@localhost redis-3.2.8]$ make
cd src && make all
make[1]: Entering directory `/home/redis/redis-3.2.8/src'

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/home/redis/redis-3.2.8/src'

4、安装redis(安装到redis用户下)

进入src目录下,使用vi编辑Makefile文件,在文件中找到“PRIFIX?=/usr/local”,修改为你需要安装的目录,这里使用局对路径。

然后执行make install命令进行安装,安装完毕后会在安装目录下生成一些执行文件。

[redis@localhost src]$ make install

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[redis@localhost bin]$ pwd
/home/redis/redis_home/bin
[redis@localhost bin]$ ls
dump.rdb         redis-check-aof  redis-cli       redis-server
redis-benchmark  redis-check-rdb  redis-sentinel

5、编辑环境变量

在 .bash_profile文件中,注册下面的环境变量,注册后可以在任何位置直接执行redis-server命令。

在REDIS_HOME目录下创建一个conf目录,把启动Redis的conf文件放在里面。

redis.conf文件在redis-3.2.8的源码目录里面。

export REDIS_HOME=/home/redis/redis_home
export PATH=${REDIS_HOME}/bin:${PATH};
[redis@localhost conf]$ pwd
/home/redis/redis_home/conf
[redis@localhost conf]$ ls
redis.conf

二、如何启动Redis


 Redis 启动很简单,直接在任意位置执行redis-server命令即可,但是由于没有运行在后台,关闭终端后Redis的进程会终止。

因此,需要对Redis的启动进行设置,使用vi编辑redis.conf文件,找到daemonize属性,把后面的no修改为yes后保存。

在redis-server的后面指定redis.conf的路径就可以了。

[redis@localhost conf]$ redis-server
21209:C 29 Apr 02:32:54.052 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
21209:M 29 Apr 02:32:54.052 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
21209:M 29 Apr 02:32:54.052 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
21209:M 29 Apr 02:32:54.052 # Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 21209
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

21209:M 29 Apr 02:32:54.053 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
21209:M 29 Apr 02:32:54.053 # Server started, Redis version 3.2.8
21209:M 29 Apr 02:32:54.053 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
21209:M 29 Apr 02:32:54.054 * DB loaded from disk: 0.000 seconds
21209:M 29 Apr 02:32:54.054 * The server is now ready to accept connections on port 6379

下面是在$REDIS_HOME/conf目录下,以deamon的方式执行redis-server。

可以看到TCP=127.0.0.1,PORT=6379,这两个参数都可以在redis.conf中进行修改。

[redis@localhost conf]$ redis-server redis.conf 
[redis@localhost conf]$ ps -ef | grep redis
root      20887  20647  0 02:20 pts/1    00:00:00 su - redis
redis     20888  20887  0 02:20 pts/1    00:00:00 -bash
redis     21322      1  0 02:42 ?        00:00:00 redis-server 127.0.0.1:6379
redis     21330  20888  0 02:42 pts/1    00:00:00 ps -ef
redis     21331  20888  0 02:42 pts/1    00:00:00 grep redis

三、使用客户端连接Redis


 在$REDIS_HOME/bin目录下,有名为redis-cli的客户端程序。

到此为止,Redis3.2.8的安装就完成了,下面就可以学习如何使用了。

[redis@bogon ~]$ redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

 

posted @ 2017-05-11 18:39  大尾巴狼R  阅读(8516)  评论(0编辑  收藏  举报